//
//  MSUserBaseController.m
//  MSJD
//
//  Created by 箭军刘 on 2018/12/10.
//  Copyright © 2018 xiangbo. All rights reserved.
//

#import "MSUserBaseController.h"

@interface MSUserBaseController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation MSUserBaseController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initNavigationBar];
    [self initSubViews];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

#pragma mark - Init Method

/** 添加导航条控件 */
- (void)initNavigationBar {
    [self addBackNavigationBarButtonWithSEL:@selector(backButtonClick)];
}

- (void)initSubViews {
    
    self.view.backgroundColor = rgb(242, 242, 242);
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.offset(0);
    }];
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.customDataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return [self loadCustomCellWithTableView:tableView Index:indexPath];
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    [self didSelectTableView:tableView indexPath:indexPath];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [self caculateCellHeightWithIndexPath:indexPath];
}

#pragma mark - Event Response

/** 返回按钮点击 */
- (void)backButtonClick {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Private Method

- (UITableViewCell *)loadCustomCellWithTableView:(UITableView *)tableView Index:(NSIndexPath *)indexPath {
    
    return [UITableViewCell alloc];
}

- (void)didSelectTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    
}
/** 计算cell的高度 */
- (CGFloat)caculateCellHeightWithIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

#pragma mark - Setter And Getter

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
    }
    return _tableView;
}

#pragma mark -  Memory Method

- (void)dealloc {
    NSLog(@"%s", __func__);
}

@end
